package main

import (
	"encoding/json"
	"fmt"
)

/**
 * @author: guangcheng
 * @date:   2020/11/20 16:47
 * @version  V1.0
 * @description:
 *
 */
func main() {

	var m1 Monster
	m1.Name = "蜘蛛精"
	m1.Age = 200

	marshal, err := json.Marshal(m1)
	if err != nil {
		fmt.Println("序列化失败")
	} else {
		//转成字符串,否则现实数字
		//{"name":"蜘蛛精","age":200}
		fmt.Println(string(marshal))
	}
}

type Monster struct {
	//大写转小写底层是反射
	Name string `json:"name"`
	Age  int    `json:"age"`
}
